<?php

App::uses('AppModel', 'Model');

class Match extends AppModel {

    var $useTable = 'matchs'; // nome della tabella

    public $actsAs = array('Slug');
    
	public $belongsTo = array(
	        'registryLocalteam' => array(
	            'className'    => 'Team' 
	            ,'foreignKey' => 'localteam_id'
	        ) 
	        ,'registryVisitorteam' => array(
	            'className'    => 'Team' 
	            ,'foreignKey' => 'visitorteam_id'
	        ) 
	);

    public $hasMany = array(
        'Event' => array(
            'className'     => 'Event',
            'foreignKey'    => 'match_id',
            'order'         => 'Event.dt_ins DESC'
        )
        ,'Localteam_substitution' => array(
            'className'     => 'Substitution',
            'foreignKey'    => 'match_id',
            'order'         => 'Localteam_substitution.dt_ins DESC',
            'conditions'	=> array('team'=>'localteam',"minute >" => 0)
        )
        ,'Visitorteam_substitution' => array(
            'className'     => 'Substitution',
            'foreignKey'    => 'match_id',
            'order'         => 'Visitorteam_substitution.dt_ins DESC',
            'conditions'	=> array('team'=>'visitorteam',"minute >" => 0)
        )
        ,'Localteam' => array(
            'className'     => 'Lineups',
            'foreignKey'    => 'match_id',
            'order'         => 'number',
            'conditions'	=> array('team'=>'localteam')
        )
        ,'Visitorteam' => array(
            'className'     => 'Lineups',
            'foreignKey'    => 'match_id',
            'order'         => 'number',
            'conditions'	=> array('team'=>'visitorteam')
        )
	);

}

?>